package cn.bdqn.service.course;

import cn.bdqn.dao.course.CourseVideoMapper;
import cn.bdqn.pojo.course.CourseVideo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CourseVideoService {
    @Autowired
    private CourseVideoMapper courseVideoMapper;

    //查询所有视频信息
    public List<CourseVideo> selectAllCourseVideo(){
        return  courseVideoMapper.selectList(null);
    }

    //根据视频名称查询
    public List<CourseVideo> selectCourseVideoByName(String name){
        return courseVideoMapper.selectList(new QueryWrapper<CourseVideo>().like("",name));
    }

    //根据课程id查询视频
    public List<CourseVideo> selectCourseVideoByCourseId(Integer courseId){
        return courseVideoMapper.selectCourseVideoByCourseId(courseId);
    }

    //根据用户id查询视频信息
    public List<CourseVideo> selectCourseVideoByUserId(Integer userId){
        return courseVideoMapper.selectList(new QueryWrapper<CourseVideo>().eq("course_video_user_id",userId));
    }

    //添加视频信息
    public Integer insertCourseVideo(CourseVideo courseVideo){
        return courseVideoMapper.insertCourseVideo(courseVideo);
    }

    //根据视频id修改视频状态
    public Integer updateCourseVideoStatusById(Integer id,Integer status){
        return courseVideoMapper.update(null,new UpdateWrapper<CourseVideo>().eq("course_video_id",id).set("course_video_status",status));
    }
    //根据id删除视频
    public Integer deleteCourseVideoById(Integer id) {
        return  courseVideoMapper.delete(new QueryWrapper<CourseVideo>().eq("course_video_id",id));
    }

    //根据目录id删除视频
    public int deleteCourseVideoByCatalogId(Integer catalogId){
        return courseVideoMapper.delete(new QueryWrapper<CourseVideo>().eq("course_catalog_id", catalogId));
    }

    //根据课程id删除视频信息
    public int deleteCourseVideoByCourseId(Integer courseId){
        return courseVideoMapper.deleteCourseVideoByCourseId(courseId);
    }

    //动态修改视频信息
    public Integer updateCourseVideo(CourseVideo courseVideo){
        return  courseVideoMapper.updateCourseVideo(courseVideo);
    }

}
